 IFNDEF _LIBRARY_
 DEFINE _LIBRARY_
 DEFINE LibraryRAM, SPace=ROM
 DEFINE LibrarySpace, Space=ROM
 DEFINE LibraryTable, Space=ROM

 INCLUDE "settings.inc"
 IFDEF TI83P
 INCLUDE "ti83plus.inc"
 ENDIF
 IFDEF TI73
 INCLUDE "ti73asm.inc"
 ENDIF

 INCLUDE "expression.inc"
 EXTERN ConvVal8Bit,ConvVal16Bit,ConvVal16BitDE,ErrorH,Variables,LoadToVar,SlideFlags,PutSApp,VPutSApp
 EXTERN SlidePtr,SlideDepth,SlideStack,LdHLIndConvVal,LdDEHLIndConvVal,LoadCoords
 EXTERN SkipThisNextRet,SkipNextCmdRet,SaveTextStuff,RestoreTextStuff,DoQuit

SkipNextCmd equ 0           ;Why does this have to be here and not externed?
SkipThisNext EQU 1
Counter EQU 0
LibRoutine MACRO label
_&label EQU Counter
;       db Counter 
       dw  _&label&_
       .eval Counter+1,Counter
       PUBLIC _&label
 ENDMAC
 
LibTableEntry MACRO label
       db     &label&Lib
       dw     &label&Table
       dw     &label&Next
 ENDMAC
CreateLibrary Macro label,first,second,third,fourth,fifth,sixth,seventh,eighth, ninth, tenth,eleventh,twelvth,n13th,n14th,n15th,n16th,n17th,n18th,n19th,n20th,n21th,n22th,n23th,n24th



 EXTERN &label&Lib
 SEGMENT LibraryTable
       LibTableEntry &label
 SEGMENT LibrarySpace
&label&Table:
 ifneq "_&first" ,"_"
 LibRoutine first
 DEFINE __&first
 DEFINE _S_&first
 endif
 ifneq "_&second" , "_"
 LibRoutine second
 DEFINE __&second
 DEFINE _S_&second
 endif
 ifneq "_&third" , "_"
 LibRoutine third
 DEFINE __&third
 DEFINE _S_&third
 endif
 ifneq "_&fourth" , "_"
 LibRoutine fourth
 DEFINE __&fourth
 DEFINE _S_&fourth
 endif
 ifneq "_&fifth" ,"_"
 LibRoutine fifth
 DEFINE __&fifth
 DEFINE _S_&fifth
 endif
 ifneq "_&sixth" , "_"
 LibRoutine sixth
 DEFINE __&sixth
 DEFINE _S_&sixth
 endif
 ifneq "_&seventh" , "_"
 LibRoutine seventh
 DEFINE __&seventh
 DEFINE _S_&seventh
 endif
 ifneq "_&eighth" , "_"
 LibRoutine eighth
 DEFINE __&eighth
 DEFINE _S_&eighth
 endif
 ifneq "_&ninth" ,"_"
 LibRoutine ninth
 DEFINE __&ninth
 DEFINE _S_&ninth
 endif
 ifneq "_&tenth" , "_"
 LibRoutine tenth
 DEFINE __&tenth
 DEFINE _S_&tenth
 endif
 ifneq "_&eleventh" , "_"
 LibRoutine eleventh
 DEFINE __&eleventh
 DEFINE _S_&eleventh
 endif
 ifneq "_&twelvth" , "_"
 LibRoutine twelvth
 DEFINE __&twelvth
 DEFINE _S_&twelvth
 endif
 ifneq "_&n13th" ,"_"
 LibRoutine n13th
 DEFINE __&n13th
 DEFINE _S_&n13th
 endif
 ifneq "_&n14th" , "_"
 LibRoutine n14th
 DEFINE __&n14th
 DEFINE _S_&n14th
 endif
 ifneq "_&n15th" , "_"
 LibRoutine n15th
 DEFINE __&n15th
 DEFINE _S_&n15th
 endif
 ifneq "_&n16th" , "_"
 LibRoutine n16th
 DEFINE __&n16th
 DEFINE _S_&n16th
 endif
  ifneq "_&n17th" ,"_"
 LibRoutine n17th
 DEFINE __&n17th
 DEFINE _S_&n17th
 endif
 ifneq "_&n18th" , "_"
 LibRoutine n18th
 DEFINE __&n18th
 DEFINE _S_&n18th
 endif
 ifneq "_&n19th" , "_"
 LibRoutine n19th
 DEFINE __&n19th
 DEFINE _S_&n19th
 endif
 ifneq "_&n20th" , "_"
 LibRoutine n20th
 DEFINE __&n20th
 DEFINE _S_&n20th
 endif
 ifneq "_&n21th" ,"_"
 LibRoutine n21th
 DEFINE __&n21th
 DEFINE _S_&n21th
 endif
 ifneq "_&n22th" , "_"
 LibRoutine n22th
 DEFINE __&n22th
 DEFINE _S_&n22th
 endif
 ifneq "_&n23th" , "_"
 LibRoutine n23th
 DEFINE __&n23th
 DEFINE _S_&n23th
 endif
 ifneq "_&n24th" , "_"
 LibRoutine n24th
 DEFINE __&n24th
 DEFINE _S_&n24th
 endif
  SEGMENT LibrarySpace
 ENDMAC


DB8BIT MACRO label
 if label<8000h
 db label
 endif
 if label>=8000h
 db label-8000h+128
 endif
 ENDMAC

CreateRoutine MACRO libname,label,num8,num16
       EXTERN _&label
       
 if num8=0
 if num16=0
label MACRO
       db     &libname&Lib,_&label
 ENDMAC
 endif
 endif

 if num8=1
 if num16=0
label MACRO first
       db     &libname&Lib,_&label
       DB8BIT first
 ENDMAC
 endif
 endif

 if num8=0
 if num16=1
label MACRO first
       db     &libname&Lib,_&label
       dw     first
 ENDMAC
 endif
 endif

 if num8=1
 if num16=1
label MACRO first,second
       db     &libname&Lib,_&label
       DB8BIT first
       dw     second
 ENDMAC
 endif
 endif


 if num8=2
 if num16=0
label MACRO first,second
       db     &libname&Lib,_&label
       DB8BIT first
       DB8BIT second
 ENDMAC
 endif
 endif

 if num8=0
 if num16=2
label MACRO first,second
       db     &libname&Lib,_&label
       dw     first,second
 ENDMAC
 endif
 endif

 if num8=3
 if num16=0
label MACRO first,second,third
       db     &libname&Lib,_&label
       DB8BIT first
       DB8BIT second
       DB8BIT third
 ENDMAC
 endif
 endif

 if num8=2
 if num16=1
label MACRO first,second,third
       db     &libname&Lib,_&label
       DB8BIT first
       DB8BIT second
       dw     third
 ENDMAC
 endif
 endif

 if num8=1
 if num16=2
label MACRO first,second,third
       db     &libname&Lib,_&label
       DB8BIT first
       dw     second,third
 ENDMAC
 endif
 endif

 if num8=0
 if num16=3
label MACRO first,second,third
       db     &libname&Lib,_&label
       dw     first,second,third
 ENDMAC
 endif
 endif

 if num8=4
 if num16=0
label MACRO first,second,third,fourth
       db     &libname&Lib,_&label
       DB8BIT first
       DB8BIT second
       DB8BIT third
       DB8BIT fourth
 ENDMAC
 endif
 endif

 if num8=3
 if num16=1
label MACRO first,second,third,fourth
       db     &libname&Lib,_&label
       DB8BIT first
       DB8BIT second
       DB8BIT third
       dw     fourth
 ENDMAC
 endif
 endif

 if num8=2
 if num16=2
label MACRO first,second,third,fourth
       db     &libname&Lib,_&label
       DB8BIT first
       DB8BIT second
       dw     third,fourth
 ENDMAC
 endif
 endif

 if num8=1
 if num16=3
label MACRO first,second,third,fourth
       db     &libname&Lib,_&label
       DB8BIT first
       dw     second,third,fourth
 ENDMAC
 endif
 endif

 if num8=0
 if num16=4
label MACRO first,second,third,fourth
       db     &libname&Lib,_&label
       dw     first,second,third,fourth
 ENDMAC
 endif
 endif      

 if num8=5
 if num16=0
label MACRO first,second,third,fourth,fifth
       db     &libname&Lib,_&label
       DB8BIT first
       DB8BIT second
       DB8BIT third
       DB8BIT fourth
       DB8BIT fifth
 ENDMAC
 endif
 endif

 if num8=4
 if num16=1
label MACRO first,second,third,fourth,fifth
       db     &libname&Lib,_&label
       DB8BIT first
       DB8BIT second
       DB8BIT third
       DB8BIT fourth
       dw     fifth
 ENDMAC
 endif
 endif

 if num8=3
 if num16=2
label MACRO first,second,third,fourth,fifth
       db     &libname&Lib,_&label
       DB8BIT first
       DB8BIT second
       DB8BIT third
       dw     fourth,fifth
 ENDMAC
 endif
 endif

 if num8=2
 if num16=3
label MACRO first,second,third,fourth,fifth
       db     &libname&Lib,_&label
       DB8BIT first
       DB8BIT second
       dw     third,fourth,fifth
 ENDMAC
 endif
 endif

 if num8=1
 if num16=4
label MACRO first,second,third,fourth,fifth
       db     &libname&Lib,_&label
       DB8BIT first
       dw     second,third,fourth,fifth
 ENDMAC
 endif
 endif

 if num8=0
 if num16=5
label MACRO first,second,third,fourth,fifth
       db     &libname&Lib,_&label
       dw     first,second,third,fourth,fifth
 ENDMAC
 endif
 endif

 ENDMAC

RAMVar MACRO label,size
 SEGMENT LibraryRAM
label ds size
 Segment LibrarySpace
 ENDMAC



byte equ 1
word equ 2
Byte equ 1
Word equ 2
float equ 9
Float equ 9

 ENDIF

